package com.itheima.d6_Set;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public class SetDemo2 {
    // 1. Set集合把重复内容去掉
    // 判断重复的条件： hashcode 和 equals 相同
    // 默认情况下，这种student是不算重复的，因为new出来的地址不同；
    // 怎么办？  Hashcode 一样； equals一样
    public static void main(String[] args) {
        Set<Student> sets = new HashSet<>();
        Student s1 = new Student("pxf",28);
        Student s2 = new Student("pxf",28);
        Student s3 = new Student("rs",26);
        sets.add(s1);
        sets.add(s2);
        sets.add(s3);
        System.out.println(sets);
    }
}

class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}